#include "Portal.h"
#include "..\\SGD Wrappers\\SGD_GraphicsManager.h"
#include "MovingObject.h"
#include "Game.h"
#include "Player.h"
#include "GameplayState.h"

Portal::Portal()
{
	m_hImage = SGD::GraphicsManager::GetInstance()->LoadTexture("resource/Graphics/portal.png");
	m_szSize.height = 64;
	m_szSize.width = 32;
}


Portal::~Portal()
{
	SGD::GraphicsManager::GetInstance()->UnloadTexture(m_hImage);
}

void Portal::Render()
{
	// Draw the image
	//SGD::GraphicsManager::GetInstance()->DrawTexture(
	//	m_hImage, m_ptPosition,
	//	m_fRotation, m_szSize);

	SGD::Rectangle renderRect;
	renderRect.left = m_ptPosition.x - (m_szSize.width / 2) - Game::GetInstance()->GetCameraPos().x;
	renderRect.top = m_ptPosition.y - Game::GetInstance()->GetCameraPos().y;
	renderRect.right = renderRect.left + m_szSize.width;
	renderRect.bottom = renderRect.top + m_szSize.height;

	switch (type)
	{
	case PortalType::PORTAL_BASE:
	{
									//SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(196, 255, 255, 255));
									SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 255, 255, 255, 255 }, { 0.5f, 1.0f });

	}
		break;
	case PortalType::PORTAL_LOADLEVEL:
	{
		switch (level)
		{
		case 0:
			 SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(255, 255, 255, 255));
			 break;
		case 1:
			 //SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(196, 0, 0, 255));
			 if (GameplayState::GetInstance()->GetPlayer()->GetNextLevel() >= 1)
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 255, 255, 255, 255 }, { 0.5f, 1.0f });
			 else
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 128, 128, 128, 128 }, { 0.5f, 1.0f });
			 break;
		case 2:
			 //SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(196, 0, 0, 192));
			 if (GameplayState::GetInstance()->GetPlayer()->GetNextLevel() >= 2)
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 255, 255, 255, 255 }, { 0.5f, 1.0f });
			 else
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 128, 128, 128, 128 }, { 0.5f, 1.0f });
			 break;
		case 3:
			 //SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(196, 0, 0, 128));
			 if (GameplayState::GetInstance()->GetPlayer()->GetNextLevel() >= 3)
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 255, 255, 255, 255 }, { 0.5f, 1.0f });
			 else
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 128, 128, 128, 128 }, { 0.5f, 1.0f });
			 break;
		case 4:
			 //SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(196, 0, 0, 64));
			 if (GameplayState::GetInstance()->GetPlayer()->GetNextLevel() >= 4)
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 255, 255, 255, 255 }, { 0.5f, 1.0f });
			 else
				 SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 128, 128, 128, 128 }, { 0.5f, 1.0f });
			 break;
		default:
			 break;
		}
	}
		break;
	case PortalType::PORTAL_PLAYERLEVEL:
	{
										   //SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(196, 0, 0, 0));
										   SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 255, 255, 0, 0 }, { 0.5f, 1.0f });

	}
		break;
	case PortalType::PORTAL_HIDDENAREA:
	{
										  //SGD::GraphicsManager::GetInstance()->DrawRectangle(renderRect, SGD::Color(196, 0, 255, 0));
										  SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, renderRect.GetTopLeft(), {}, {}, { 255, 255, 255, 255 }, { 0.5f, 1.0f });

	}
		break;
	default:
		break;
	}

	if (myEmitter)
		myEmitter->Render();
}

void Portal::HandleCollision(GameObject* pOther)
{
	if (pOther->GetType() == MovingObject::OBJ_PLAYER)
	{
		isColliding = true;
	}
}

SGD::Rectangle Portal::GetRect(void) const
{
	return SGD::Rectangle(m_ptPosition, m_szSize);
}